package cn.yunhe.pojo;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Entity(name = "学生")
@Table(name = "student")
public class Student implements Serializable {
    private int sid;
    private String sname;
    private Set<Course> courseSet=new HashSet<>();

    public Student() {
    }

    public Student(String sname) {
        this.sname = sname;
    }

    public Student(String sname, Set<Course> courseSet) {
        this.sname = sname;
        this.courseSet = courseSet;
    }

    public Student(int sid, String sname, Set<Course> courseSet) {
        this.sid = sid;
        this.sname = sname;
        this.courseSet = courseSet;
    }

    @Id
    @GeneratedValue
    @Column(name = "sid")
    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    @Column(name = "sname")
    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    @ManyToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY,mappedBy = "studentSet")
    /*@JoinTable(name = "m_course_student",
            joinColumns = @JoinColumn(name="msid"),
            inverseJoinColumns = @JoinColumn(name="mcid")
    )*/
    public Set<Course> getCourseSet() {
        return courseSet;
    }

    public void setCourseSet(Set<Course> courseSet) {
        this.courseSet = courseSet;
    }
}
